From 114f16d3fb3b7bc53879e7e8f602987a5b2902c3 Mon Sep 17 00:00:00 2001 From: "emellor@leeni.uk.xensource.com" Date: Thu, 24 Nov 2005 19:56:38 +0000 Subject: [PATCH] Programmatically generate the xm help strings from the snippets, rather than splicing the strings together manually. Replace the word "bogus" with the command in question where it appears, as this shows up in the Usage statements. Signed-off-by: Ewan Mellor --- tools/python/xen/xm/main.py | 213 ++++++++++++++++++------------------ 1 file changed, 104 insertions(+), 109 deletions(-) diff --git a/tools/python/xen/xm/main.py b/tools/python/xen/xm/main.py index 092282ceaa..e1f8a1a62d 100644 --- a/tools/python/xen/xm/main.py +++ b/tools/python/xen/xm/main.py @@ -24,7 +24,6 @@ import os import os.path import sys -import commands import re from getopt import getopt import socket @@ -71,7 +70,7 @@ vcpu_list_help = "vcpu-list List the VCPUs for a domain ( vcpu_pin_help = "vcpu-pin Set which cpus a VCPU can use" dmesg_help = "dmesg [--clear] Read or clear Xen's message buffer" info_help = "info Get information about the xen host" -log_help = "log Print the xend log" +log_help = "log Print the xend log" sched_bvt_help = """sched-bvt Set Borrowed Virtual Time scheduler parameters""" sched_bvt_ctxallow_help = """sched-bvt-ctxallow Set the BVT scheduler context switch @@ -96,25 +95,87 @@ vnet_create_help = "vnet-create create a vnet from a config vnet_delete_help = "vnet-delete delete a vnet" +short_command_list = [ + "console", + "create", + "destroy", + "help", + "list", + "mem-max", + "mem-set", + "migrate", + "pause", + "reboot", + "restore", + "save", + "shutdown", + "top", + "unpause", + ] + +domain_commands = [ + "console", + "create", + "destroy", + "domid", + "domname", + "list", + "mem-max", + "mem-set", + "migrate", + "pause", + "reboot", + "restore", + "save", + "shutdown", + "sysrq", + "top", + "unpause", + "set-vcpus", + "vcpu-pin", + ] + +host_commands = [ + "dmesg", + "info", + "log", + "top", + ] + +scheduler_commands = [ + "sched-bvt", + "sched-bvt-ctxallow", + "sched-sedf", + ] + +device_commands = [ + "block-attach", + "block-detach", + "block-list", + "network-attach", + "network-detach", + "network-list", + ] + +vnet_commands = [ + "vnet-list", + "vnet-create", + "vnet-delete", + ] + +all_commands = (domain_commands + host_commands + scheduler_commands + + device_commands + vnet_commands) + + +def commandToHelp(cmd): + return eval(cmd.replace("-", "_") + "_help") + + shorthelp = """Usage: xm [args] Control, list, and manipulate Xen guest instances -xm common subcommands:""" + help_spacer \ -+ console_help + help_spacer \ -+ create_help + help_spacer \ -+ destroy_help + help_spacer \ -+ help_help + help_spacer \ -+ list_help + help_spacer \ -+ mem_max_help + help_spacer \ -+ mem_set_help + help_spacer \ -+ migrate_help + help_spacer \ -+ pause_help + help_spacer \ -+ reboot_help + help_spacer \ -+ restore_help + help_spacer \ -+ save_help + help_spacer \ -+ shutdown_help + help_spacer \ -+ top_help + help_spacer \ -+ unpause_help + """ +xm common subcommands: + """ + help_spacer.join(map(commandToHelp, short_command_list)) + """ can be substituted for in xm subcommands. @@ -127,50 +188,20 @@ longhelp = """Usage: xm [args] xm full list of subcommands: - Domain Commands: """ + help_spacer \ -+ console_help + help_spacer \ -+ create_help + help_spacer \ -+ destroy_help + help_spacer \ -+ domid_help + help_spacer \ -+ domname_help + help_spacer \ -+ list_help + help_spacer \ -+ mem_max_help + help_spacer \ -+ mem_set_help + help_spacer \ -+ migrate_help + help_spacer \ -+ pause_help + help_spacer \ -+ reboot_help + help_spacer \ -+ restore_help + help_spacer \ -+ save_help + help_spacer \ -+ shutdown_help + help_spacer \ -+ sysrq_help + help_spacer \ -+ top_help + help_spacer \ -+ unpause_help + help_spacer \ -+ set_vcpus_help + help_spacer \ -+ vcpu_pin_help + """ - - Xen Host Commands: """ + help_spacer \ -+ dmesg_help + help_spacer \ -+ info_help + help_spacer \ -+ log_help + help_spacer \ -+ top_help + """ - - Scheduler Commands: """ + help_spacer \ -+ sched_bvt_help + help_spacer \ -+ sched_bvt_ctxallow_help + help_spacer \ -+ sched_sedf_help + """ - - Virtual Device Commands:""" + help_spacer \ -+ block_attach_help + help_spacer \ -+ block_detach_help + help_spacer \ -+ block_list_help + help_spacer \ -+ network_attach_help + help_spacer \ -+ network_detach_help + help_spacer \ -+ network_list_help + """ - - Vnet commands: """ + help_spacer \ -+ vnet_list_help + help_spacer \ -+ vnet_create_help + help_spacer \ -+ vnet_delete_help + """ + Domain Commands: + """ + help_spacer.join(map(commandToHelp, domain_commands)) + """ + + Xen Host Commands: + """ + help_spacer.join(map(commandToHelp, host_commands)) + """ + + Scheduler Commands: + """ + help_spacer.join(map(commandToHelp, scheduler_commands)) + """ + + Virtual Device Commands: + """ + help_spacer.join(map(commandToHelp, device_commands)) + """ + + Vnet commands: + """ + help_spacer.join(map(commandToHelp, vnet_commands)) + """ can be substituted for in xm subcommands. @@ -180,48 +211,14 @@ For more help on xm create, see the xmdomain.cfg(5) man page""" # array for xm help help = { - "--long": longhelp, - "console": console_help, -# create is handled specially - "destroy": destroy_help, - "domid ": domid_help, - "domname": domname_help, - "list": list_help, - "mem-max": mem_max_help, - "mem-set": mem_set_help, - "migrate": migrate_help, - "pause": pause_help, - "reboot": reboot_help, - "restore": restore_help, - "save": save_help, - "shutdown": shutdown_help, - "sysrq": sysrq_help, - "unpause": unpause_help, - "set-vcpus": set_vcpus_help, - "vcpu-list": vcpu_list_help, - "vcpu-pin": vcpu_pin_help, -# Xen Host Commands: - "dmesg": dmesg_help, - "info": info_help, - "log": log_help, - "top": top_help, -# Scheduler Commands: - "sched-bvt": sched_bvt_help, - "sched-bvt-ctxallow": sched_bvt_ctxallow_help, - "sched-sedf": sched_sedf_help, - -# Virtual Device Commands: - "block-attach": block_attach_help, - "block-detach": block_detach_help, - "block-list": block_list_help, - "network-attach": network_attach_help, - "network-detach": network_detach_help, - "network-list": network_list_help, -# Vnet commands: - "vnet-list": vnet_list_help, - "vnet-create": vnet_create_help, - "vnet-delete": vnet_delete_help - } + "--long": longhelp + } + +for command in all_commands: + # create is handled specially + if (command != 'create'): + help[command] = commandToHelp(command) + #################################################################### # @@ -484,9 +481,7 @@ def xm_vcpu_list(args): def xm_reboot(args): arg_check(args,1,"reboot") from xen.xm import shutdown - # ugly hack because the opt parser apparently wants - # the subcommand name just to throw it away! - shutdown.main(["bogus", "-R"] + args) + shutdown.main(["shutdown", "-R"] + args) def xm_pause(args): arg_check(args, 1, "pause") @@ -504,7 +499,7 @@ def xm_unpause(args): def xm_subcommand(command, args): cmd = __import__(command, globals(), locals(), 'xen.xm') - cmd.main(["bogus"] + args) + cmd.main([command] + args) ############################################################# @@ -632,7 +627,7 @@ its contents if the [-c|--clear] flag is specified. use="Clear the contents of the Xen message buffer.") # Work around for gopts myargs = args - myargs.insert(0, "bogus") + myargs.insert(0, 'dmesg') gopts.parse(myargs) if not (1 <= len(myargs) <= 2): err('Invalid arguments: ' + str(myargs)) -- 2.30.2